package net.openadventure.hotspot;

import java.awt.Polygon;
import java.util.LinkedHashMap;

import net.openadventure.EgoAction;
import net.openadventure.MouseAction;
import net.openadventure.MouseContext;

public class Hotspot {

	private Polygon area;

	private LinkedHashMap<String, HotspotHandler> handlers = new LinkedHashMap<String, HotspotHandler>();

	public Polygon getArea() {
		return area;
	}
	
	public void setArea(Polygon area) {
		this.area = area;
	}

	public void setMouseHandler(MouseAction action, MouseContext context, HotspotHandler handler) {
		handlers.put("mouse[" + action.name() + "|" + context.name() + "]", handler);
	}
	
	public HotspotHandler getMouseHandler(MouseAction action, MouseContext context) {
		return tryGettingHandler("mouse[" + action.name() + "|" + context.name() + "]");
	}
	
	public void setEgoHandler(EgoAction action, HotspotHandler handler) {
		handlers.put("ego[" + action + "]", handler);
	}
	
	public HotspotHandler getEgoHandler(EgoAction action) {
		return tryGettingHandler("ego[" + action + "]");
	}
	
	private HotspotHandler tryGettingHandler(String handlerName) {
		HotspotHandler handler = handlers.get(handlerName);

		if (handler != null) {
			return handler;
		} else {
			return new HotspotHandler("");
		}
	}
}
